﻿namespace NTLib.IOC.Containers
{
    using System;
    using System.Threading;

    /// <summary>
    /// Contains only one instance
    /// </summary>
    /// <seealso cref="NTLib.IOC.Containers.IContainer" />
    public class InstanceContainer : TypeContainer
    {
        #region Fields

        private readonly object _instance;

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the <see cref="InstanceContainer{TInstance}"/> class.
        /// </summary>
        public InstanceContainer(object instance, Type key)
            : base (instance.GetType(), key, false)
        {
            this._instance = instance;
        }

        /// <summary>
        /// Gets the specified instance.
        /// </summary>
        /// <typeparam name="TInstance1">The type of the instance1.</typeparam>
        /// <param name="state">The state.</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public override TInstance Get<TInstance>(object state = null, CancellationToken token = default(CancellationToken))
        {
            return (TInstance)this._instance;
        }

        #endregion
    }
}
